﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using App.Core.Extensions;
using App.Data;

public partial class Pages_Public_SpecialOfferDetails : BasePage
{
    protected int _OfferID;

    protected void Page_Load(object sender, EventArgs e)
    {
        BindPageInfo();
        if (!IsPostBack)
        {
            BindSpecialOfferDetails();
        }
    }
    protected void BindPageInfo()
    {
        _OfferID = WebUtil.GetQueryStringInInt(AppConstants.QueryString.ID);
        Page.Title = WebUtil.GetPageTitle(h4Heading.InnerHtml);
    }

    protected void BindSpecialOfferDetails()
    {
        BtcHousingEntities context = new BtcHousingEntities();
        var entity = context.SpecialOffers.FirstOrDefault(P => P.ID == _OfferID);
        if (entity == null)
            ShowNotFoundMessage();
        else
        {
            divTitle.InnerHtml = entity.Title.HtmlEncode();
            divDate.InnerHtml = entity.Created.ToString(AppConstants.ValueOf.DATE_FROMAT_DISPLAY);
            divDescription.InnerHtml = WebUtil.FormatText(entity.Description);

            if (!entity.Picture.IsNullOrEmpty())
            {
                OfferImageFile.InnerHtml = String.Format("<img class='EventImage' src='{0}/{1}' alt='' title='' />", AppConstants.SPECIAL_OFFER_IMAGES, entity.Picture);
                OfferImageFile.Visible = true;
            }
        }
    }
    protected void ShowNotFoundMessage()
    {
        WebUtil.ShowMessageBox(divMessage, "Sorry! Requested Special Offer Was not found.", true);
        pnlFormContainer.Visible = false;
    }
}